home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / CUGUK / UTIL_SRC / C016.ZIP / CALC / SYMBOL.C < prev    next >
Text File  |  1990-01-19  |  1KB  |  59 lines

  1. /* $Author: jkcohen $
  2.  * $Source: /mnt1/h/jkcohen/Source/C/Hoc/RCS/symbol.c,v $
  3.  * $Revision: 1.1 $ ; $Date: 87/03/16 21:18:21 $
  4.  * $State: Stab $
  5. */
  6.  
  7. #include "su.h"
  8. #include "jc.h"
  9. #include "hoc.h"
  10. #include "ytab.h"
  11.  
  12. static Symbol *symlist = 0;    /* symbol table: linked list */
  13.  
  14. Symbol *lookup(s)    /* find s in symbol table */
  15. register char *s;
  16. Begin
  17.     register Symbol *sp;
  18.  
  19.     For sp = symlist; sp != (Symbol *) 0; sp = sp->next Do
  20.         If strcmp(sp->name, s) == 0 Do
  21.             Return sp;
  22.         Endif
  23.     Endfor
  24.     Return 0;        /* 0 ==> not found */
  25. End
  26.  
  27.  
  28. Symbol *install(s, t, d)    /* install s in symbol table */
  29. register char *s;
  30. register int t;
  31. double d;
  32. Begin
  33.     register Symbol *sp;
  34.     char *emalloc();
  35.  
  36.     sp = (Symbol *) emalloc(sizeof(Symbol));
  37.     sp->name = emalloc(strlen(s) + 1);  /* +1 for '\0' */
  38.     strcpy(sp->name, s);
  39.     sp->type = t;
  40.     sp->u.val = d;
  41.     sp->next = symlist;  /* put at front of list */
  42.     symlist = sp;
  43.     Return sp;
  44. End
  45.  
  46.  
  47. char *emalloc(n)        /* check return from malloc */
  48. register unsigned n;
  49. Begin
  50.     register char *p;
  51.     char *malloc();
  52.  
  53.     p = malloc(n);
  54.     If p == 0 Do
  55.         execerror("out of memory", (char *) 0);
  56.     Endif
  57.     Return p;
  58. End
  59.